/**
 * 
 */
function spasiPomjeranje(mark)
{
	var req = createRequest(); // defined above
	//Create the callback:
	req.onreadystatechange = function() {
	if (req.readyState != 4) return; // Not there yet
	if (req.status != 200) {
	 // Handle request failure here...
	 return;
	}
	// Request successful, read the response
	var resp= req.responseText;
	alert(resp);
	// ... and use it as needed by your app.
	//alert(r2);
			  
	return;
	};
	
	parametri="?id="+mark.id+"&GSirina="+mark.getPosition().lng()+"&GDuzina="+mark.getPosition().lat();
	req.open("GET","korisno/stanice/pomjeri"+parametri, true);
	req.send();
}
function poveziStanice() {
	if (k > 1) {
		//alert(markers[0].position);
		var dvotacka = [ markers[k - 2].position, markers[k - 1].position ];
		var putanja = new google.maps.Polyline({
			path : dvotacka,
			geodesic : true,
			strokeColor : '#FF0000',
			strokeOpacity : 1.0,
			strokeWeight : 2

		});
		putanja.setMap(map);
		veze.push(putanja);
	}
}
function pomjeri(marker) {
	//alert(marker.naziv+" "+marker.redosljed+" markers: " + markers.length);
	spasiPomjeranje(marker);
	var i = marker.redosljed;
	if (i > 0 && i < markers.length - 1) {
		veze[i-1].setMap(null);
		veze[i].setMap(null);
		veze[i-1] = new google.maps.Polyline({
			path : [ markers[i-1].position, marker.position ],
			geodesic : true,
			strokeColor : '#FF0000',
			strokeOpacity : 1.0,
			strokeWeight : 2

		});
		veze[i] = new google.maps.Polyline({
			path : [ marker.position, markers[i + 1].position ],
			geodesic : true,
			strokeColor : '#FF0000',
			strokeOpacity : 1.0,
			strokeWeight : 2

		});
		veze[i-1].setMap(map);
		veze[i].setMap(map);
	}
	else if(i==0&&markers.length>1){
		veze[i].setMap(null);
		veze[i] = new google.maps.Polyline({
			path : [ marker.position, markers[i + 1].position ],
			geodesic : true,
			strokeColor : '#FF0000',
			strokeOpacity : 1.0,
			strokeWeight : 2

		});
		veze[i].setMap(map);
		
	}
	else if(i==markers.length-1&&i!=0)
		{
		veze[i-1].setMap(null);
		veze[i-1] = new google.maps.Polyline({
			path : [ markers[i-1].position, marker.position ],
			geodesic : true,
			strokeColor : '#FF0000',
			strokeOpacity : 1.0,
			strokeWeight : 2

		});
		veze[i-1].setMap(map);
		
		}
}